﻿@page "/login"
@page "/"
@layout LoginLayout
@using BootstrapBlazor.Components
@using System.Diagnostics.CodeAnalysis
@using System.Text
@inject SqlSugarScope _SqlSugarScope
@inject ToastService ToastService


<body class="body" data-typography="poppins" data-theme-version="light" data-layout="vertical"
data-nav-headerbg="color_3" data-headerbg="color_3" data-sidebar-style="full" data-sidebarbg="color_1"
data-sidebar-position="fixed" data-header-position="fixed" data-container="wide" direction="ltr"
data-primary="color_1">
    <div class="authincation d-flex flex-column flex-lg-row flex-column-fluid">
        <div class="login-aside text-center  d-flex flex-column flex-row-auto">
            <div class="d-flex flex-column-auto flex-column pt-lg-40 pt-15">
                <h3 class="mb-2 text-white">中顺生物BI平台</h3>
                <p class="mb-4">发现数据的力量，释放决策的潜力</p>
            </div>
            <div class="aside-image position-relative" >
                <img class="img1 " src="/images/pic3.png" alt="">
                <img class="img2 " src="/images/pic4.png" alt="">
                <img class="img3 " src="/images/pic5.png" alt="">
            </div>
        </div>
        <div
        class="container flex-row-fluid d-flex flex-column justify-content-center position-relative overflow-hidden p-7 mx-auto">
            <div class="d-flex justify-content-center h-100 align-items-center">
                <div class="authincation-content style-2">
                    <div class="row no-gutters">
                        <div class="col-xl-12 tab-content">
                            <div id="sign-up" class="auth-form tab-pane fade show active  form-validation">
                                <form action="Account/login" method="get">
                                    <div>
                                        <div class="text-center mb-4">
                                            <h3 class="text-center mb-2 text-dark">登录系统</h3>
                                            <span>请输入您的账号密码</span>
                                        </div>


                                    </div>
                                    <div class="mb-3">
                                        <label for="exampleFormControlInput1" class="form-label">账号</label>

                                        <input type="text" Class="form-control" name="username" />
                                    </div>
                                    <div class="mb-3 position-relative">
                                        <label class="form-label">密码</label>

                                        <input type="password" Class="form-control" name="password" />
                                        <span class="show-pass eye">
                                            <i class="fa fa-eye-slash"></i>
                                            <i class="fa fa-eye"></i>
                                        </span>
                                    </div>
                                    <button  class="btn btn-block btn-primary" type="submit">登录</button>
                                    @* <ButtonUpload TValue="string" IsMultiple="false" ShowProgress="true" OnChange="@OnClickToUpload" OnDelete="@(fileName => Task.FromResult(true))"></ButtonUpload> *@
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</body>

@* <form action="Account/login" method="get">
        <table summary="this is a form">
            <tr>
                <td class="th">用户名：</td>
                <td><input type="text" name="username" /></td>
            </tr>
            <tr>
                <td class="th">密码：</td>
                <td> <input type="password" name="password" /></td>
            </tr>
            <tr>
                <td class="th"> <button class="btn btn-primary" type="submit">登录</button></td>
            </tr>
        </table>
    </form> *@
@code {


    [Inject]
    [NotNull]
    private MessageService? messageService { get; set; }

    private CancellationTokenSource? ReadToken { get; set; }
    bool ret = false;
    private async Task OnClickToUpload(UploadFile file)
    {
        if (file == null || file.OriginFileName == null)
    {
        return;
    }

        // Server Side 使用
        // Web Assembly 模式下必须使用 WebApi 方式去保存文件到服务器或者数据库中
        // 生成写入文件名称
        var ret = false;
        string path = Path.GetTempPath();
        if (!string.IsNullOrEmpty(path))
        {
            var uploaderFolder = Path.Combine(path, "POS_U8_InvPrice");
            file.FileName = $"{Path.GetFileNameWithoutExtension(file.OriginFileName)}-{DateTimeOffset.Now:yyyyMMddHHmmss}{Path.GetExtension(file.OriginFileName)}";
            var fileName = Path.Combine(uploaderFolder, DateTime.Now.ToFileTime()+file.FileName);

            ReadToken ??= new CancellationTokenSource();
            ret = await file.SaveToFileAsync(fileName, 5 * 1024 * 1024, ReadToken.Token);

            if (ret)
            {
                List<Data.dbmodels.POS_U8_InvPrice> data =  MiniExcelLibs.MiniExcel.Query<Data.dbmodels.POS_U8_InvPrice>(fileName).ToList();
                await ToastService.Information("上传文件", "成功");
            }
            else
            {
                var errorMessage = $"{"保存文件失败"} {file.OriginFileName}";
                file.Code = 1;
                file.Error = errorMessage;
                await ToastService.Error("上传文件", errorMessage);
            }
        }
    }
}
